package com.czp.framework.util;

import java.sql.Timestamp;
import java.util.Calendar;

/**
 *
 * 【描 述】：日期操作工具类
 * 【环 境】：J2SE 1.7
 * 
 * @author   柴志鹏
 * @version  version 1.0
 * @since    2014-5-30
 */
public class DateUtils {
	
	/** 
	 * 【描 述】：获取当前系统时间
	 * @return (Timestamp) yyyy-MM-dd HH:mm:ss
	 */
	public static Timestamp getSysTimestamp() {
		return new Timestamp(System.currentTimeMillis());
	}
	
	/** 
	 * 【描 述】：获取当前系统年份
	 * @return (String) YYYY
	 */
	public static String getCurrentYear() {
		Calendar c = Calendar.getInstance();
		return String.valueOf(c.get(Calendar.YEAR));
	}
	
	/** 
	 * 【描 述】：将字符串时间转换为Timestamp时间类型
	 * @param (String) yyyy-MM-dd HH:mm:ss
	 * @return (Timestamp) yyyy-MM-dd HH:mm:ss
	 */
	public static Timestamp getTimestamp(String dateStr) {
		Timestamp rtValue = null;
		if ((dateStr == null) || (dateStr.length() == 0))
			return null;
		try {
			rtValue = Timestamp.valueOf(dateStr);
		} catch (Exception e) {
			dateStr = dateStr.trim() + " 00:00:00";
			try {
				rtValue = Timestamp.valueOf(dateStr);
			} catch (RuntimeException re) {
				re.printStackTrace();
			}
		}
		return rtValue;
	}
	
	public static void main(String args[]) {
		System.out.println(getSysTimestamp());
		System.out.println(getCurrentYear());
	}
}
